home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_541 / steal / src / steal.c < prev   
C/C++ Source or Header  |  1992-05-06  |  18KB  |  741 lines

  1. /****************************************************************************
  2.  
  3.                 Steal.c
  4.  
  5.     This file contains the main definitions of Steal 1.1 by Rick van
  6.     Rein. Please, do not be shocked at the sight FiniteStateMachine ();
  7.     Those goto's are the logical implementation of a finite state
  8.     machine; This is also structured programming, only different
  9.     from the conventional way. I thought it would suit answering
  10.     to Intuition's messages better.
  11.  
  12.                     Rick van Rein, November 4, 1990
  13.  
  14. ****************************************************************************/
  15.  
  16.  
  17.  
  18. #include <functions.h>
  19. #include <exec/types.h>
  20. #include <exec/lists.h>
  21. #include <intuition/intuition.h>
  22. #include <intuition/intuitionbase.h>
  23.  
  24.  
  25. int OpenPrintFile ();
  26. void ClosePrintFile ();
  27. void mprintf ();
  28.  
  29. /* The routines that perform the real action of stealing: */
  30.  
  31. int PrintScreen ();
  32. int PrintWindow ();
  33. int PrintMenu ();
  34. int PrintGadget ();
  35.  
  36.  
  37. struct IntuitionBase *IntuitionBase;
  38. struct GfxBase *GfxBase;
  39.  
  40. struct Window *win;
  41.  
  42. struct Image *StdCheckMark;    /* For reference by the Print module */
  43.  
  44. static struct TextAttr StdTextAttr=
  45.  {
  46.    (UBYTE *) "topaz.font",
  47.    8,
  48.    FS_NORMAL,
  49.    NULL
  50.  };
  51.  
  52. struct TextFont *StdFont;    /* For ALL IntuiTexts; contains Topaz 8. Use it! */
  53.  
  54. static struct IntuiMessage *LastIntuiMessage=NULL;
  55.  
  56.  
  57. #define TOTALIDCMP    ( GADGETUP | GADGETDOWN | CLOSEWINDOW | INACTIVEWINDOW )
  58.  
  59. #define BLUE_0      0
  60. #define WHITE_1     1
  61. #define BLACK_2     2
  62. #define ORANGE_3    3
  63.  
  64.  
  65. SHORT xy0 []=
  66.  {
  67.    5,12,
  68.    634,12,
  69.    634,61,
  70.    5,61,
  71.    5,12
  72.  };
  73.  
  74. struct Border bor0=        /* Inner border for Window */
  75.  {
  76.    -100,-22,                    /* LeftEdge,TopEdge */
  77.    ORANGE_3,BLUE_0,                /* FrontPen, BackPen */
  78.    JAM1,                    /* DrawMode */
  79.    5,                        /* Count */
  80.    xy0,                        /* XY */
  81.    NULL                        /* NextBorder */
  82.  };
  83.  
  84. SHORT xy1 []=
  85.  {
  86.    -4,-3,
  87.    448,-3,
  88.    448,14,
  89.    -4,14,
  90.    -4,-3
  91.  };
  92.  
  93. struct Border bor1=
  94.  {
  95.    -80,-2,                    /* LeftEdge,TopEdge */
  96.    ORANGE_3,BLUE_0,                /* FrontPen, BackPen */
  97.    JAM1,                    /* DrawMode */
  98.    5,                        /* Count */
  99.    xy1,                        /* XY */
  100.    &bor0                    /* NextBorder */
  101.  };
  102.  
  103. SHORT xy2 []=
  104.  {
  105.    -1,-1,
  106.    445,-1,
  107.    445,12,
  108.    -1,12,
  109.    -1,-1
  110.  };
  111.  
  112. struct Border bor2=
  113.  {
  114.    -80,-2,                    /* LeftEdge,TopEdge */
  115.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  116.    JAM1,                    /* DrawMode */
  117.    5,                        /* Count */
  118.    xy2,                        /* XY */
  119.    &bor1                    /* NextBorder */
  120.  };
  121.  
  122. struct IntuiText itx1=
  123.  {
  124.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  125.    JAM1,                    /* DrawMode */
  126.    -76,0,                    /* LeftEdge, TopEdge */
  127.    NULL,                    /* ITextFont */
  128.    (UBYTE *) "FileName:",            /* IText */
  129.    NULL                        /* NextText */
  130.  };
  131.  
  132. struct IntuiText itx2=
  133.  {
  134.    BLACK_2,BLUE_0,                /* FrontPen, BackPen */
  135.    JAM1,                    /* DrawMode */
  136.    -75,1,                    /* LeftEdge, TopEdge */
  137.    NULL,                    /* ITextFont */
  138.    (UBYTE *) "FileName:",            /* IText */
  139.    &itx1                    /* NextText */
  140.  };
  141.  
  142. char str1 [201]="";
  143.  
  144. char undo1 [201];
  145.  
  146. struct StringInfo sin1=
  147.  {
  148.    (UBYTE *) str1,(UBYTE *) undo1,        /* Buffer,UndoBuffer */
  149.    0,                        /* BufferPos */
  150.    201,                        /* MaxChars */
  151.    0                        /* DispPos */
  152.     /* Intuition initializes and maintains all other variables for you */
  153.  };
  154.  
  155. struct Gadget gad1=
  156.  {
  157.    NULL,                    /* NextGadget */
  158.    100,22,                    /* LeftEdge,TopEdge */
  159.    365,8,                    /* Width,Height */
  160.    GADGHCOMP,                    /* Flags */
  161.    GADGIMMEDIATE | RELVERIFY,            /* Activation */
  162.    STRGADGET,                    /* GadgetType */
  163.    (APTR) &bor2,                /* GadgetRender (Border) */
  164.    NULL,                    /* SelectRender */
  165.    &itx2,                    /* GadgetText */
  166.    0x00000000,                    /* MutualExclude */
  167.    (APTR) &sin1,                /* SpecialInfo (StringInfo) */
  168.    1,                        /* GadgetID */
  169.    0x00000000,                    /* UserData */
  170.  };
  171.  
  172. SHORT xy3 []=
  173.  {
  174.    -4,-3,
  175.    138,-3,
  176.    138,14,
  177.    -4,14,
  178.    -4,-3
  179.  };
  180.  
  181. struct Border bor3=
  182.  {
  183.    0,0,                        /* LeftEdge,TopEdge */
  184.    ORANGE_3,BLUE_0,                /* FrontPen, BackPen */
  185.    JAM1,                    /* DrawMode */
  186.    5,                        /* Count */
  187.    xy3,                        /* XY */
  188.    NULL                        /* NextBorder */
  189.  };
  190.  
  191. SHORT xy4 []=
  192.  {
  193.    -1,-1,
  194.    135,-1,
  195.    135,12,
  196.    -1,12,
  197.    -1,-1
  198.  };
  199.  
  200. struct Border bor4=
  201.  {
  202.    0,0,                        /* LeftEdge,TopEdge */
  203.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  204.    JAM1,                    /* DrawMode */
  205.    5,                        /* Count */
  206.    xy4,                        /* XY */
  207.    &bor3                    /* NextBorder */
  208.  };
  209.  
  210. struct IntuiText itx3=
  211.  {
  212.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  213.    JAM1,                    /* DrawMode */
  214.    19,2,                    /* LeftEdge, TopEdge */
  215.    NULL,                    /* ITextFont */
  216.    (UBYTE *) "Steal Screen",            /* IText */
  217.    NULL                        /* NextText */
  218.  };
  219.  
  220. struct IntuiText itx4=
  221.  {
  222.    BLACK_2,BLUE_0,                /* FrontPen, BackPen */
  223.    JAM1,                    /* DrawMode */
  224.    20,3,                    /* LeftEdge, TopEdge */
  225.    NULL,                    /* ITextFont */
  226.    (UBYTE *) "Steal Screen",            /* IText */
  227.    &itx3                    /* NextText */
  228.  };
  229.  
  230. struct Gadget gad2=
  231.  {
  232.    &gad1,                    /* NextGadget */
  233.    20,42,                    /* LeftEdge,TopEdge */
  234.    135,12,                    /* Width,Height */
  235.    GADGHCOMP,                    /* Flags */
  236.    RELVERIFY,                    /* Activation */
  237.    BOOLGADGET,                    /* GadgetType */
  238.    (APTR) &bor4,                /* GadgetRender (Border) */
  239.    NULL,                    /* SelectRender */
  240.    &itx4,                    /* GadgetText */
  241.    0x00000000,                    /* MutualExclude */
  242.    NULL,                    /* SpecialInfo (BoolInfo) */
  243.    2,                        /* GadgetID */
  244.    0x00000000,                    /* UserData */
  245.  };
  246.  
  247. struct IntuiText itx5=
  248.  {
  249.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  250.    JAM1,                    /* DrawMode */
  251.    19,2,                    /* LeftEdge, TopEdge */
  252.    NULL,                    /* ITextFont */
  253.    (UBYTE *) "Steal Window",            /* IText */
  254.    NULL                        /* NextText */
  255.  };
  256.  
  257. struct IntuiText itx6=
  258.  {
  259.    BLACK_2,BLUE_0,                /* FrontPen, BackPen */
  260.    JAM1,                    /* DrawMode */
  261.    20,3,                    /* LeftEdge, TopEdge */
  262.    NULL,                    /* ITextFont */
  263.    (UBYTE *) "Steal Window",            /* IText */
  264.    &itx5                    /* NextText */
  265.  };
  266.  
  267. struct Gadget gad3=
  268.  {
  269.    &gad2,                    /* NextGadget */
  270.    175,42,                    /* LeftEdge,TopEdge */
  271.    135,12,                    /* Width,Height */
  272.    GADGHCOMP,                    /* Flags */
  273.    RELVERIFY,                    /* Activation */
  274.    BOOLGADGET,                    /* GadgetType */
  275.    (APTR) &bor4,                /* GadgetRender (Border) */
  276.    NULL,                    /* SelectRender */
  277.    &itx6,                    /* GadgetText */
  278.    0x00000000,                    /* MutualExclude */
  279.    NULL,                    /* SpecialInfo (BoolInfo) */
  280.    3,                        /* GadgetID */
  281.    0x00000000,                    /* UserData */
  282.  };
  283.  
  284. struct IntuiText itx7=
  285.  {
  286.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  287.    JAM1,                    /* DrawMode */
  288.    23,2,                    /* LeftEdge, TopEdge */
  289.    NULL,                    /* ITextFont */
  290.    (UBYTE *) "Steal Menu",            /* IText */
  291.    NULL                        /* NextText */
  292.  };
  293.  
  294. struct IntuiText itx8=
  295.  {
  296.    BLACK_2,BLUE_0,                /* FrontPen, BackPen */
  297.    JAM1,                    /* DrawMode */
  298.    24,3,                    /* LeftEdge, TopEdge */
  299.    NULL,                    /* ITextFont */
  300.    (UBYTE *) "Steal Menu",            /* IText */
  301.    &itx7                    /* NextText */
  302.  };
  303.  
  304. struct Gadget gad4=
  305.  {
  306.    &gad3,                    /* NextGadget */
  307.    330,42,                    /* LeftEdge,TopEdge */
  308.    135,12,                    /* Width,Height */
  309.    GADGHCOMP,                    /* Flags */
  310.    RELVERIFY,                    /* Activation */
  311.    BOOLGADGET,                    /* GadgetType */
  312.    (APTR) &bor4,                /* GadgetRender (Border) */
  313.    NULL,                    /* SelectRender */
  314.    &itx8,                    /* GadgetText */
  315.    0x00000000,                    /* MutualExclude */
  316.    NULL,                    /* SpecialInfo (BoolInfo) */
  317.    4,                        /* GadgetID */
  318.    0x00000000,                    /* UserData */
  319.  };
  320.  
  321. struct IntuiText itx9=
  322.  {
  323.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  324.    JAM1,                    /* DrawMode */
  325.    19,2,                    /* LeftEdge, TopEdge */
  326.    NULL,                    /* ITextFont */
  327.    (UBYTE *) "Steal Gadget",            /* IText */
  328.    NULL                        /* NextText */
  329.  };
  330.  
  331. struct IntuiText itx10=
  332.  {
  333.    BLACK_2,BLUE_0,                /* FrontPen, BackPen */
  334.    JAM1,                    /* DrawMode */
  335.    20,3,                    /* LeftEdge, TopEdge */
  336.    NULL,                    /* ITextFont */
  337.    (UBYTE *) "Steal Gadget",            /* IText */
  338.    &itx9                    /* NextText */
  339.  };
  340.  
  341. struct Gadget gad5=
  342.  {
  343.    &gad4,                    /* NextGadget */
  344.    485,42,                    /* LeftEdge,TopEdge */
  345.    135,12,                    /* Width,Height */
  346.    GADGHCOMP,                    /* Flags */
  347.    RELVERIFY,                    /* Activation */
  348.    BOOLGADGET,                    /* GadgetType */
  349.    (APTR) &bor4,                /* GadgetRender (Border) */
  350.    NULL,                    /* SelectRender */
  351.    &itx10,                    /* GadgetText */
  352.    0x00000000,                    /* MutualExclude */
  353.    NULL,                    /* SpecialInfo (BoolInfo) */
  354.    5,                        /* GadgetID */
  355.    0x00000000,                    /* UserData */
  356.  };
  357.  
  358. struct IntuiText itx11=
  359.  {
  360.    WHITE_1,BLUE_0,                /* FrontPen, BackPen */
  361.    JAM1,                    /* DrawMode */
  362.    19,2,                    /* LeftEdge, TopEdge */
  363.    NULL,                    /* ITextFont */
  364.    (UBYTE *) "Cancel action",            /* IText */
  365.    NULL                        /* NextText */
  366.  };
  367.  
  368. struct IntuiText itx12=
  369.  {
  370.    BLACK_2,BLUE_0,                /* FrontPen, BackPen */
  371.    JAM1,                    /* DrawMode */
  372.    20,3,                    /* LeftEdge, TopEdge */
  373.    NULL,                    /* ITextFont */
  374.    (UBYTE *) "Cancel action",            /* IText */
  375.    &itx11                    /* NextText */
  376.  };
  377.  
  378. struct Gadget gad6=
  379.  {
  380.    &gad5,                    /* NextGadget */
  381.    485,20,                    /* LeftEdge,TopEdge */
  382.    135,12,                    /* Width,Height */
  383.    GADGHCOMP,                    /* Flags */
  384.    RELVERIFY,                    /* Activation */
  385.    BOOLGADGET,                    /* GadgetType */
  386.    (APTR) &bor4,                /* GadgetRender (Border) */
  387.    NULL,                    /* SelectRender */
  388.    &itx12,                    /* GadgetText */
  389.    0x00000000,                    /* MutualExclude */
  390.    NULL,                    /* SpecialInfo (BoolInfo) */
  391.    6,                        /* GadgetID */
  392.    0x00000000,                    /* UserData */
  393.  };
  394.  
  395. struct NewWindow nwin=
  396.  {
  397.    0,12,                    /* LeftEdge,TopEdge */
  398.    640,64,                    /* Width,Height */
  399.    BLUE_0,WHITE_1,                /* DetailPen,BlockPen */
  400.    TOTALIDCMP,                    /* IDCMPFlags */
  401.    WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | SIMPLE_REFRESH | ACTIVATE | WINDOWACTIVE | WINDOWTICKED,
  402.                         /* Flags */
  403.    &gad6,                    /* FirstGadget */
  404.    NULL,                    /* CheckMark */
  405.    (UBYTE *) "Steal 1.1 --- Copyright 1990 Rick van Rein ",
  406.                            /* Title */
  407.    NULL,                    /* Screen */
  408.    NULL,                    /* BitMap */
  409.    640,64,                    /* MinWidth,MinHeight */
  410.    640,64,                    /* MaxWidth,MaxHeight */
  411.    WBENCHSCREEN                    /* Type */
  412.  };
  413. #define filename str1
  414.  
  415.  
  416.  
  417. /***** Report an error, that was given as a string: */
  418.  
  419. char REPORT_COPYRIGHT []="Steal 1.1 --- Copyright 1990 Rick van Rein ";
  420. char REPORT_BUSY []="Steal 1.1 --- Sneaking into Intuition right now - Hold your breath ";
  421. char REPORT_SEL_SCREEN []="Steal 1.1 --- Select a Screen or Cancel ";
  422. char REPORT_SEL_WINDOW []="Steal 1.1 --- Select a Window or Cancel ";
  423. char REPORT_SEL_MENU []="Steal 1.1 --- Select a Window with a Menu or Cancel ";
  424. char REPORT_SEL_GADGET []="Steal 1.1 --- Select a Gadget or Cancel ";
  425.  
  426. char ERR_CANCEL []="Steal 1.1 --- Cancel selected ";
  427. char ERR_NOWINDOW []="Steal 1.1 --- No Window at mouse position ";
  428. char ERR_NOMENU []="Steal 1.1 --- That Window does not bear a Menu ";
  429. char ERR_NOGADGET []="Steal 1.1 --- No Gadget at mouse position ";
  430. char ERR_NOFILE []="Steal 1.1 --- Can't open file - Try again please ";
  431. char ERR_NOSCREEN []="Steal 1.1 --- No Screen is available (?) ";
  432.  
  433. void Error (str)
  434.    char *str;
  435.  {
  436.    SetWindowTitles (win,str,-1L);    /* Leave Screens title alone */
  437.    ActivateWindow (win);        /* To make title better readable */
  438.    ScreenToFront (win->WScreen);
  439.    DisplayBeep (0L);
  440.  }
  441.  
  442. void Report (str)
  443.    char *str;
  444.  {
  445.    SetWindowTitles (win,str,-1L);
  446.  }
  447.  
  448. /***** The GADGETUP have internal names, see below. Decode an IMsg and find the internal type: */
  449.  
  450. #define GUP_STR        0x01000000L
  451. #define GUP_SCREEN    0x02000000L
  452. #define GUP_WINDOW    0x04000000L
  453. #define GUP_MENU    0x08000000L
  454. #define GUP_GADGET    0x10000000L
  455. #define GUP_CANCEL    0x20000000L
  456. #define GUP_STEAL    ( GUP_SCREEN | GUP_WINDOW | GUP_MENU | GUP_GADGET )
  457.  
  458. long DecodeIDCMP (imsg)
  459.    struct IntuiMessage *imsg;
  460.  {
  461.    long class=imsg->Class;
  462.  
  463.    if (class & GADGETUP)
  464.       class=GUP_STR << (((struct Gadget *) imsg->IAddress)->GadgetID -1);
  465.    return class;
  466.  }
  467.  
  468.  
  469. /***** Get an IntuiMessage that suits us right now; sel uses internal IDCMP-codes: */
  470.  
  471.  
  472.        /* NOTE: Before we return an IntuiMessage, we first ReplyMsg the last one we returned, if any */
  473.  
  474. struct IntuiMessage *GetIDCMP (sel)
  475.    long sel;
  476.  {
  477.    struct Node *this,*next;
  478.  
  479.    if (LastIntuiMessage)
  480.     {
  481.       ReplyMsg (LastIntuiMessage);
  482.       LastIntuiMessage=NULL;
  483.     }
  484.  
  485.    do
  486.     {
  487.       WaitPort (win->UserPort);
  488.       this=(struct Node *) GetMsg (win->UserPort);
  489.       if (sel & DecodeIDCMP (this))
  490.          return (LastIntuiMessage=(struct IntuiMessage *) this);    /* Indeed an assignment! */
  491.       else
  492.      ReplyMsg (this);
  493.     }
  494.    while (1);                /* Escape this loop with return */
  495.  }
  496.  
  497.  
  498.  
  499. /***** Find the Gadget on which the mouse is currently; Also give the Error if needed: */
  500.  
  501. struct Gadget *FindActiveGadget ()
  502.  {
  503.    struct Gadget *gad;
  504.    struct Window *wdw;
  505.    struct Screen *scr;
  506.    int x,y,relx,rely;
  507.  
  508.    wdw=IntuitionBase->ActiveWindow;
  509.    if (!wdw)
  510.     {
  511.       Error (ERR_NOWINDOW);
  512.       return NULL;
  513.     }
  514.    scr=wdw->WScreen;    /* Of course it's there! What else should contain this window? */
  515.  
  516.    x=scr->MouseX - wdw->LeftEdge;    /* MouseX relative to Window */
  517.    y=scr->MouseY - wdw->TopEdge;    /* MouseY relative to Window */
  518.  
  519.    gad=wdw->FirstGadget;
  520.    while (gad)
  521.     {
  522.       relx=x - gad->LeftEdge;        /* MouseX relative to Gadget */
  523.       rely=y - gad->TopEdge;        /* MouseY relative to Gadget */
  524.       if (gad->Flags & GRELRIGHT)
  525.          relx-=wdw->Width-1;
  526.       if (gad->Flags & GRELBOTTOM)
  527.          rely-=wdw->Height-1;
  528.  
  529.       if (relx>=0 && rely>=0 && relx<gad->Width && rely<gad->Height)
  530.          return gad;            /* Found it!!! */
  531.  
  532.       gad=gad->NextGadget;
  533.     }
  534.  
  535.    Error (ERR_NOGADGET);
  536.    return NULL;
  537.  }
  538.  
  539.  
  540.  
  541. /***** The finite state machine: */
  542.  
  543. void FiniteStateMachine ()
  544.  {
  545.    ULONG IBaseLock;
  546.    struct IntuiMessage *im;
  547.    long oldclass;
  548.    struct Window *wdw;
  549.    struct Screen *scr;
  550.    struct Gadget *gad;
  551.    int nr;
  552.  
  553.     /* State 0: Activate the string and start inputing it: */
  554.    ACT_START:
  555.       ActivateGadget (&gad1,win,0L);
  556.  
  557.     /* State 1: Input a string in the (now active) string-Gadget */
  558.    START:
  559.       im=GetIDCMP (GADGETDOWN | CLOSEWINDOW | GUP_STR | GUP_STEAL | GUP_CANCEL);
  560.       if (im->Class==GADGETDOWN)
  561.      goto START;
  562.       if (im->Class==CLOSEWINDOW)
  563.          goto EXIT;
  564.       if (DecodeIDCMP (im)==GUP_CANCEL)
  565.      DisplayBeep (0L);
  566.  
  567.     /* Test if the file with the given stringname can be opened: */
  568.       if (!OpenPrintFile (filename))
  569.        {
  570.          Error (ERR_NOFILE);
  571.          goto ACT_START;
  572.        }
  573.       Report (REPORT_COPYRIGHT);
  574.  
  575.       if (DecodeIDCMP (im) & (GUP_STEAL | CLOSEWINDOW))
  576.          goto LOOPTEST;
  577.  
  578.     /* State 2: Wait for some signal from the IDCMP in this main WAIT-STATE */
  579.    LOOP:
  580.       im=GetIDCMP (CLOSEWINDOW | GADGETDOWN | GUP_STEAL);
  581.  
  582.           /* State 3: Process the signal that was last read: */
  583.    LOOPTEST:
  584.       oldclass=DecodeIDCMP (im);
  585.       if (oldclass==CLOSEWINDOW)
  586.          goto CLOSE_EXIT;
  587.       if (oldclass==GADGETDOWN)        /* Only string reports GADGETDOWN */
  588.          goto NEWSTRING;
  589.  
  590.     /* State 4: We now have to steal. Wait for INACTIVEWINDOW to tell us what to steal: */
  591.    STEAL:
  592.       switch (oldclass)                /* Ask user to click item to be stolen */
  593.        {
  594.          case GUP_SCREEN:
  595.         Report (REPORT_SEL_SCREEN);
  596.         break;
  597.          case GUP_WINDOW:
  598.         Report (REPORT_SEL_WINDOW);
  599.             break;
  600.          case GUP_MENU:
  601.         Report (REPORT_SEL_MENU);
  602.             break;
  603.          case GUP_GADGET:
  604.         Report (REPORT_SEL_GADGET);
  605.             break;
  606.        }
  607.  
  608.                /* Now, before looking at what item the user selected, first be sure all IntuiMsgs
  609.            that were still pending are gone: */
  610.       while (im = (struct IntuiMessage *) GetMsg (win->UserPort))
  611.          ReplyMsg (im);
  612.       im=GetIDCMP (CLOSEWINDOW | INACTIVEWINDOW | GUP_CANCEL | GUP_STEAL | GADGETDOWN);
  613.       if (im->Class==CLOSEWINDOW)
  614.          goto CLOSE_EXIT;
  615.       if (im->Class==GADGETUP)            /* Must be a GUP_CANCEL or some GUP_STEAL */
  616.        {
  617.          if (DecodeIDCMP (im) & GUP_STEAL)
  618.         goto LOOPTEST;
  619.      else
  620.       {
  621.             Error (ERR_CANCEL);
  622.         goto LOOP;
  623.           }
  624.        }
  625.       if (im->Class==GADGETDOWN)        /* This must have been the string-Gadget. Timing ??? */
  626.          goto NEWSTRING;
  627.  
  628.       Report (REPORT_BUSY);
  629.       IBaseLock = LockIBase (0L);
  630.       switch (oldclass)
  631.        {
  632.          case GUP_SCREEN:
  633.             goto STEALSCREEN;
  634.          case GUP_WINDOW:
  635.             goto STEALWINDOW;
  636.          case GUP_MENU:
  637.             goto STEALMENU;
  638.          case GUP_GADGET:
  639.             goto STEALGADGET;
  640.        }
  641.  
  642.    STEALSCREEN:
  643.       if (scr=IntuitionBase->ActiveScreen)
  644.        {
  645.          nr=PrintScreen (scr);
  646.      goto REPORT;
  647.        }
  648.       Error (ERR_NOSCREEN);
  649.       goto JUSTLOOP;
  650.  
  651.    STEALWINDOW:
  652.       if (wdw=IntuitionBase->ActiveWindow)
  653.        {
  654.          nr=PrintWindow (wdw,0);
  655.      goto REPORT;
  656.        }
  657.       Error (ERR_NOWINDOW);
  658.       goto JUSTLOOP;
  659.  
  660.    STEALMENU:
  661.       if (wdw=IntuitionBase->ActiveWindow)
  662.        {
  663.          if (!wdw->MenuStrip)
  664.       {
  665.         Error (ERR_NOMENU);
  666.         goto JUSTLOOP;
  667.       }
  668.          nr=PrintMenu (wdw->MenuStrip);
  669.      goto REPORT;
  670.        }
  671.       Error (ERR_NOWINDOW);
  672.       goto JUSTLOOP;
  673.  
  674.    STEALGADGET:
  675.       if (gad=FindActiveGadget ())
  676.        {
  677.          nr=PrintGadget (gad,0);
  678.      goto REPORT;
  679.        }
  680.       goto JUSTLOOP;
  681.  
  682.    NEWSTRING:
  683.       ClosePrintFile ();
  684.       goto START;
  685.  
  686.    REPORT:
  687.       Error (REPORT_COPYRIGHT);
  688.  
  689.    JUSTLOOP:
  690.       UnlockIBase (IBaseLock);
  691.       goto LOOP;
  692.  
  693.    CLOSE_EXIT:
  694.       ClosePrintFile ();
  695.  
  696.    EXIT:
  697.       ;
  698.  }
  699.  
  700.  
  701. int main ()
  702.  {
  703.    if (!(IntuitionBase=(struct IntuitionBase *) OpenLibrary ("intuition.library",0L)))
  704.     {
  705.       puts ("\tSteal: Can't open intuition.library somehow (?)");
  706.       exit (0);
  707.     }
  708.    if (!(GfxBase=(struct GfxBase *) OpenLibrary ("graphics.library",0L)))
  709.     {
  710.       puts ("\tSteal: Can't open graphics.library somehow (?)");
  711.       CloseLibrary (IntuitionBase);
  712.       exit (0);
  713.     }
  714.  
  715.    strcpy (filename,"Stolen.c");
  716.  
  717.    if (win=OpenWindow (&nwin))
  718.     {
  719.       StdCheckMark=win->CheckMark;
  720.       StdFont=(struct TextFont *) OpenFont (&StdTextAttr);
  721.       win->IFont=StdFont;
  722.       SetFont (win->RPort,StdFont);
  723.       SetFont (win->BorderRPort,StdFont);
  724.  
  725.       FiniteStateMachine ();
  726.  
  727.       if (LastIntuiMessage)
  728.          ReplyMsg (LastIntuiMessage);
  729.  
  730.       if (StdFont)
  731.          CloseFont (StdFont);
  732.       CloseWindow (win);
  733.     }
  734.    else
  735.       puts ("\tSteal: Couldn't open window");
  736.  
  737.    CloseLibrary (GfxBase);
  738.    CloseLibrary (IntuitionBase);
  739.    return 0;
  740.  }
  741.